package com.controller;

import com.base.BaseController;
import com.req.UserPageReq;
import com.req.UserReq;
import com.base.BasePageRes;
import com.res.UserRes;
import com.service.UserService;
import com.util.common.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
@Api(tags = "用户")
public class UserController extends BaseController {
    @Autowired
    private UserService userService;
    @PostMapping("/save")
    @ApiOperation("用户的增删改查")
    public R<UserRes> saveArtical(@RequestBody UserReq userReq){

        return R.ok(userService.saveUser(userReq));
    }
    @PostMapping("/queryPage")
    @ApiOperation("用户分页查询")
    public R<BasePageRes> queryPage(@RequestBody UserPageReq pageReq){
        UserRes user = this.getUser();
        return R.ok(userService.queryPage(pageReq,user));
    }

    @PostMapping("/login")
    @ApiOperation("登陆")
    public R<UserRes> Login(@RequestBody UserReq userReq){

        return R.ok(userService.login(userReq));
    }
    @GetMapping("/logout")
    @ApiModelProperty("登出")
    public R logout(){
        userService.logout(this.getUser());
        return R.ok();
    }


}
